<?php

namespace App\Http\Controllers\Admin;

use App\Service\WareHouseService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class WareHouseController extends Controller
{
    //
    private $wareHouseService;
    public function __construct(WareHouseService $houseService)
    {
        $this->wareHouseService  = $houseService;
    }

    public function getWareHouseList(){
        $data = $this->wareHouseService->getWareHouseList();
        return view('warehouse_list')->with('data',$data);
    }

    public function wareHouseIn(Request $request){
        $info = $request->only('id','count');
        $this->wareHouseService->wareHouseIn($info);
        return redirect('/getWareHouseInList');
    }

    public function wareHouseOut(Request $request){
        $info = $request->only('id','count');
        $this->wareHouseService->wareHouseOut($info);
        return redirect('/getWareHouseOutList');
    }

    public function addWareHouse(){
        return view('warehouse_add');
    }

    public function doAddWareHouse(Request $request){
        $wareHouse = $request->only('name','count','inPrice','outPrice');
         $this->wareHouseService->addWareHouse($wareHouse);
        return redirect('/getWareHouseInList');
    }

    public function getWareHouseInList(){
        $data = $this->wareHouseService->getWareHouseInList()->toArray();
        return view('warehouse_in_list')->with('data',$data);
    }

    public function verifyWareHouseIn(Request $request){
        $id = $request->get('id');
        $this->wareHouseService->verifyWareHouseIn($id);
        return redirect('/getWareHouseInList');
    }

    public function getWareHouseOutList(){
        $data = $this->wareHouseService->getWareHouseOutList();
        return view('warehouse_out_list')->with('data',$data);
    }

    public function verifyWareHouseOut(Request $request){
        $id = $request->get('id');
        $this->wareHouseService->verifyWareHouseOut($id);
        return redirect('/getWareHouseOutList');
    }
}
